﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DBBase;

namespace Business
{
    public partial class QueryLog : Form
    {
        public QueryLog()
        {
            InitializeComponent();
        }
        public MainForm m_mainform;
        private void but_query_Click(object sender, EventArgs e)
        {
            //判断是否核心功能
            if (m_mainform.shxgn.Contains("接口日志查询"))
            {
                m_mainform.baocunhxrj("接口日志查询", string.Format("接口日志查询"), "查询");// 核心功能日记  日记内容
            }
            getjilu();
        }
        ///编码
        public static string EncodeBase64(string code_type, string code)
        {
            string encode = "";
            byte[] bytes = Encoding.GetEncoding(code_type).GetBytes(code);
            try
            {
                encode = Convert.ToBase64String(bytes);
            }
            catch
            {
                encode = code;
            }
            return encode;
        }
        ///解码
        public static string DecodeBase64(string code_type, string code)
        {
            string decode = "";
            byte[] bytes = Convert.FromBase64String(code);
            try
            {
                decode = Encoding.GetEncoding(code_type).GetString(bytes);
            }
            catch
            {
                decode = code;
            }
            return decode;
        }

        public void getjilu()
        {
            list.Rows.Clear();
            Query mquery = new Query();
            string sql;
            sql = string.Format(@"Select * from QueryLog Where QueryDate>'{0}' and QueryDate<'{1}' and jkid like '%%{2}%%'", dateTimePicker1.Value.ToShortDateString() + " 00:00:00", dateTimePicker2.Value.ToShortDateString() + " 23:59:59", text_jkid.Text);

            sql = sql + " order by QueryDate desc ";
            
            {
                DataTable dt = mquery.GetTable(sql);

                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        list.Rows.Add();
                        list.Rows[i].Cells[0].Value = string.Format("{0}", i + 1);
                        list.Rows[i].Cells[1].Value = dt.Rows[i]["jkid"].ToString().Trim();
                        list.Rows[i].Cells[2].Value = dt.Rows[i]["QueryDate"].ToString().Trim();
                        list.Rows[i].Cells[3].Value = DecodeBase64("utf-8", dt.Rows[i]["QueryXmlDoc"].ToString().Trim());
                        list.Rows[i].Cells[4].Value = DecodeBase64("utf-8", dt.Rows[i]["results"].ToString().Trim());
                    }
                }


            }



        }

       

        private void QueryLog_Load(object sender, EventArgs e)
        {
            //判断是否民警
            if (m_mainform.sfjy.Contains("接口日志查询"))
            {
                if (!m_mainform.SFMJ.Contains("是"))
                {
                    but_query.Enabled = false;
                }
            }
        }
    }
}
